<!doctype html>



  


<html class="theme-next mist use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/vendors/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Lato:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/vendors/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="OS," />








  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="说明：Ubuntu系统配置。">
<meta name="keywords" content="OS">
<meta property="og:type" content="article">
<meta property="og:title" content="Ubuntu系统配置">
<meta property="og:url" content="http://bebetter.site/2017/01/12/OS/Ubuntu/03系统配置/index.html">
<meta property="og:site_name" content="gatewayzy">
<meta property="og:description" content="说明：Ubuntu系统配置。">
<meta property="og:updated_time" content="2017-01-12T05:58:03.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Ubuntu系统配置">
<meta name="twitter:description" content="说明：Ubuntu系统配置。">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Mist',
    sidebar: {"position":"right","display":"always"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: 0,
      author: '博主'
    }
  };
</script>




  <link rel="canonical" href="http://bebetter.site/2017/01/12/OS/Ubuntu/03系统配置/"/>

  <title> Ubuntu系统配置 | gatewayzy </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-meta ">
  

  <div class="custom-logo-site-title">
    <a href="/"  class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <span class="site-title">gatewayzy</span>
      <span class="logo-line-after"><i></i></span>
    </a>
  </div>
  <p class="site-subtitle">blog of gatewayzy</p>
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      

      
    </ul>
  

  
</nav>

 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                Ubuntu系统配置
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">发表于</span>
            <time itemprop="dateCreated" datetime="2017-01-12T13:58:03+08:00" content="2017-01-12">
              2017-01-12
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/OS/" itemprop="url" rel="index">
                    <span itemprop="name">OS</span>
                  </a>
                </span>

                
                

              
            </span>
          

          
            
          

          

          
          

          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <p><strong>说明：</strong>Ubuntu系统配置。<br><a id="more"></a></p>
<h3 id="系统关机与系统信息"><a href="#系统关机与系统信息" class="headerlink" title="系统关机与系统信息"></a>系统关机与系统信息</h3><ul>
<li>关机<ul>
<li>shutdown -h [时间]，立即关机使用0或者now，常用 sudo shutdown -h now</li>
<li>init 0，这个是运行级别关机，需要确保系统没有在读写硬盘等操作，否则可能导致损坏</li>
<li>power off，这个命令很好用</li>
<li>halt，这个命令不太好用</li>
</ul>
</li>
<li>重启 <ul>
<li>reboot 主要用于单用户模式</li>
<li>shutdown -r [时间] 如now</li>
</ul>
</li>
<li>查看电脑型号：sudo dmidecode | grep Product 查看服务器型号，如Dell PowerEdge R730</li>
<li>查看系统运行级别 <code>runlevel</code>，ubuntu一般默认2或5。<br>  0 – Halt，关机模式<br>  1 – Single，单用户模式<br>  2 - Full multi-user with display manager (GUI)<br>  3 - Full multi-user with display manager (GUI)<br>  4 - Full multi-user with display manager (GUI)<br>  5 - Full multi-user with display manager (GUI)<br>  6 – Reboot，重启<br>  S - 单用户恢复模式</li>
<li>更改ubuntu默认系统级别：创建/etc/inittab文件，添加<code>id:5:initdefault:</code>，重启</li>
</ul>
<h3 id="系统编码"><a href="#系统编码" class="headerlink" title="系统编码"></a>系统编码</h3><p>步骤为：</p>
<ol>
<li>修改/var/lib/locales/supported.d/local文件（不存在的话可以自行创建），添加几行<code>en_US.UTF-8 UTF-8</code> <code>zh_CN.UTF-8 UTF-8</code> <code>zh_CN.GBK GBK</code> <code>zh_CN GB2312</code> <code>zh_CN.GB18030 GB18030</code></li>
<li>运行sudo dpkg-reconfigure locales，会看到勾选了上面的语言。重启ubuntu。如果仍存在部分中文乱码，运行命令<code>$ sudo apt-get install ttf-wqy-*</code> <code>$ sudo apt-get install xfonts-wqy</code> <code>$ sudo apt-get install fonts-wqy-*</code>即可显示正常。</li>
</ol>
<ul>
<li>/etc/default/locale 内容务必是 <code>LANG=&quot;en_US.UTF-8&quot;</code>，否则可能影响gnome-terminal的启动</li>
</ul>
<h3 id="使用ibus的中文输入法"><a href="#使用ibus的中文输入法" class="headerlink" title="使用ibus的中文输入法"></a>使用ibus的中文输入法</h3><p><strong>基本安装与使用</strong></p>
<ul>
<li>安装：<ul>
<li>可以先将系统编码设置为中文显示。</li>
<li>安装ibus框架：<code>sudo apt-get install ibus ibus-clutter ibus-gtk ibus-gtk3 ibus-qt4</code></li>
<li>安装输入法：<code>sudo apt-get install ibus-pinyin ibus-table-wubi ibus-sunpinyin</code></li>
</ul>
</li>
<li>配置ibus：<code>sudo ibus-setup</code>，会弹出操作界面，设置快捷键、横竖候选项、添加输入法等设置。</li>
<li>使用ibus：运行<code>ibus-daemon</code>守护进程，就可以输入中文了。默认使用的是shift进行切换。更改设置使用<code>sudo ibus-setup</code>。</li>
</ul>
<p><strong>高级配置</strong></p>
<ul>
<li>设置默认使用ibus而不是fcitx等输入框架：<ul>
<li>执行im-switch -s ibus，选中ibus即可（如果提示没有im-switch，尝试使用新版的命令im-config）。如果出错进行如下操作：<code>cd /etc/X11/xinit/xinput.d/ $ sudo cp default ibus $ sudo vim ibus</code>，修改三行<code>XIM=ibus XIM_PROGRAM=/usr/bin/ibus-daemon XIM_ARGS=&quot;—xim&quot;</code>，然后再运行im-switch -s ibus。</li>
</ul>
</li>
<li>配置ibus的自启动：<ul>
<li>每次都手动运行<code>ibus-daemon</code>守护进程，是比较麻烦的。</li>
<li>可以在~/.bashrc中添加如下内容。因为放在bashrc中，所以新打开terminal才行，也可以在~/.profile中也加上下面这段以防止没有terminal开着时ibus退出。</li>
<li>我是使用bashrc，在vnc启动中启动<code>gnome-terminal &amp;</code>，这样terminal触发了bashrc的运行。</li>
</ul>
</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div></pre></td><td class="code"><pre><div class="line">export GTK_IM_MODULE=ibus  </div><div class="line">export QT_IM_MODULE=ibus  </div><div class="line">export XIM_PROGRAM=&quot;ibus-daemon&quot;</div><div class="line">export XMODIFIERS=@im=ibus </div><div class="line">ibus-daemon -drRx</div></pre></td></tr></table></figure>
<h3 id="开机启动"><a href="#开机启动" class="headerlink" title="开机启动"></a>开机启动</h3><hr>
<p>参考文章 <a href="http://www.cnblogs.com/hongzg1982/articles/2101792.html" target="_blank" rel="external">here</a></p>
<h4 id="etc-rc-local-脚本"><a href="#etc-rc-local-脚本" class="headerlink" title="/etc/rc.local 脚本"></a>/etc/rc.local 脚本</h4><ul>
<li>在/etc/init.d/rc.local中已经说明，该文件默认在2,3,4,5级别都会运行，且如果存在/etc/rc.local，则会运行/etc/rc.local。所以下面的设置都不是必须的，</li>
<li>/etc/rc.local 系统开机时启动，属于系统核心启动的偏后期。注意其中的所有的命令都需要使用全部路径，而且由于后面需要exit 0所以只能运行一些结束性的工作。<ul>
<li>编辑 /etc/rc.local 脚本，添加运行命令，比如<code>/etc/init.d/samba start</code>。或者把任务放到其他脚本中：<ul>
<li>设置开机脚本/etc/rc.local，添加<code>bash /home/zju/sh/powerOnJobs.sh</code>，用于开机启动脚本</li>
<li>powerOnJobs.sh里面存放具体的任务内容，包括如 <code>echo &quot;密码&quot; | sudo -S sh /home/zju/sh/connectVPN.sh</code></li>
<li>这样的话，容易扩展，但是降低了安全性。</li>
</ul>
</li>
<li>查看系统运行级别<code>runlevel</code>，比如是5，为/etc/rc5.d下面添加rc.local的链接<code>ln -s ../rc.d/rc.local rc.local.ln</code>链到对应级别的配置文件夹下。</li>
</ul>
</li>
</ul>
<h4 id="profile-脚本"><a href="#profile-脚本" class="headerlink" title="~/.profile 脚本"></a>~/.profile 脚本</h4><ul>
<li>用户登录时启动<ul>
<li>终端中执行gnome-session-properties，进行添加</li>
<li>编辑用户对应的 ~/.profile， 添加运行命令。该文件在用户登录后只运行一次，常用于初始化环境变量和程序设定等操作。</li>
<li>用户对应的~/.bashrc 每个shell都会读一遍该文件。</li>
</ul>
</li>
</ul>
<h3 id="系统环境变量"><a href="#系统环境变量" class="headerlink" title="系统环境变量"></a>系统环境变量</h3><hr>
<ul>
<li>使用env查看当前环境变量，可进行grep。</li>
<li>/etc/profile 文件的环境变量对所有用户生效，且只在开机时加载。修改之后，source /etc/profile 生效，但只有该terminal有效，重启后所有terminal有效。</li>
<li>~/.profile 文件是每个用户名用户的环境变量，在用户初次登陆时加载。修改之后，source ~/.profile 生效，但只有该terminal有效，logout该用户，重新登录后有效。</li>
<li>如在/etc/profile和~/.profile中都添加如下的内容，或者用户可以自修改个人的env值。</li>
</ul>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div></pre></td><td class="code"><pre><div class="line">export JAVA_HOME=/opt/jdk1.8.0</div><div class="line">export JRE_HOME=$&#123;JAVA_HOME&#125;/jre  </div><div class="line">export CLASSPATH=.:$&#123;JAVA_HOME&#125;/lib:$&#123;JRE_HOME&#125;/lib  </div><div class="line">export M2_HOME=/opt/maven3.3.3</div><div class="line">export PATH=$PATH:$M2_HOME/bin:$JAVA_HOME/bin</div><div class="line">export NODE_HOME=/opt/node7.7.2</div><div class="line">export  PATH=$PATH:$&#123;NODE_HOME&#125;/bin</div></pre></td></tr></table></figure>

      
    </div>

    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/OS/" rel="tag">#OS</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/01/12/OS/Ubuntu/02软件与常用软件/" rel="next" title="Ubuntu软件与常用软件">
                <i class="fa fa-chevron-left"></i> Ubuntu软件与常用软件
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/12/Software/Deployment platform and configuration management 部署平台与配置管理/Puppet/" rel="prev" title="Puppet">
                Puppet <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    


  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel ">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/statics/images/avatar.png"
               alt="gatewayzy" />
          <p class="site-author-name" itemprop="name">gatewayzy</p>
          <p class="site-description motion-element" itemprop="description">blog website with hexo and github pages</p>
        </div>
        <nav class="site-state motion-element">
          <div class="site-state-item site-state-posts">
            <a href="/archives">
              <span class="site-state-item-count">70</span>
              <span class="site-state-item-name">日志</span>
            </a>
          </div>

          
            <div class="site-state-item site-state-categories">
              <a href="/categories">
                <span class="site-state-item-count">10</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            <div class="site-state-item site-state-tags">
              <a href="/tags">
                <span class="site-state-item-count">38</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        

        <div class="links-of-author motion-element">
          
        </div>

        
        

        
        
          <div class="links-of-blogroll motion-element links-of-blogroll-inline">
            <div class="links-of-blogroll-title">
              <i class="fa  fa-fw fa-globe"></i>
              友情链接
            </div>
            <ul class="links-of-blogroll-list">
              
                <li class="links-of-blogroll-item">
                  <a href="https://github.com/gatewayzy" title="Github-gatewayzy" target="_blank">Github-gatewayzy</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://google.com/" title="Goolge" target="_blank">Goolge</a>
                </li>
              
                <li class="links-of-blogroll-item">
                  <a href="http://wiki.jikexueyuan.com/" title="Wiki-jike" target="_blank">Wiki-jike</a>
                </li>
              
            </ul>
          </div>
        

      </section>

      
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">
            
              
            
            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#系统关机与系统信息"><span class="nav-number">1.</span> <span class="nav-text">系统关机与系统信息</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#系统编码"><span class="nav-number">2.</span> <span class="nav-text">系统编码</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用ibus的中文输入法"><span class="nav-number">3.</span> <span class="nav-text">使用ibus的中文输入法</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#开机启动"><span class="nav-number">4.</span> <span class="nav-text">开机启动</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#etc-rc-local-脚本"><span class="nav-number">4.1.</span> <span class="nav-text">/etc/rc.local 脚本</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#profile-脚本"><span class="nav-number">4.2.</span> <span class="nav-text">~/.profile 脚本</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#系统环境变量"><span class="nav-number">5.</span> <span class="nav-text">系统环境变量</span></a></li></ol></div>
            
          </div>
        </section>
      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">gatewayzy</span>
</div>

<div class="powered-by">
  由 <a class="theme-link" href="https://hexo.io">Hexo</a> 强力驱动
</div>

<div class="theme-info">
  主题 -
  <a class="theme-link" href="https://github.com/iissnan/hexo-theme-next">
    NexT.Mist
  </a>
</div>

        

        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  



  
  <script type="text/javascript" src="/vendors/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/vendors/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/vendors/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/vendors/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  




  
  

  
  <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        inlineMath: [ ['$','$'], ["\\(","\\)"]  ],
        processEscapes: true,
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
  </script>

  <script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
      var all = MathJax.Hub.getAllJax(), i;
      for (i=0; i < all.length; i += 1) {
        all[i].SourceElement().parentNode.className += ' has-jax';
      }
    });
  </script>
  <script type="text/javascript" src="//cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>



  

  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
